package com.sl.biz.modular.restapi.dao.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sl.biz.modular.restapi.dao.entity.ApiVersionConfigDO;
import com.sl.biz.modular.restapi.dao.mapper.ApiVersionConfigMapper;
import com.sl.biz.modular.restapi.dao.service.ApiVersionConfigDaoService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class ApiVersionConfigDaoServiceImpl extends ServiceImpl<ApiVersionConfigMapper, ApiVersionConfigDO> implements ApiVersionConfigDaoService {

    @Override
    public List<ApiVersionConfigDO> queryByApiConfigId(String apiConfigId) {
        LambdaQueryWrapper<ApiVersionConfigDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApiVersionConfigDO::getApiId, apiConfigId);
        return super.list(queryWrapper);
    }

    @Override
    public Boolean removeByApiIdAndVersion(String apiId, String apiVersion) {
        LambdaQueryWrapper<ApiVersionConfigDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApiVersionConfigDO::getApiId, apiId);
        queryWrapper.eq(ApiVersionConfigDO::getApiVersion, apiVersion);
        return super.remove(queryWrapper);
    }

    @Override
    public Boolean removeByApiId(String apiId) {
        LambdaQueryWrapper<ApiVersionConfigDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ApiVersionConfigDO::getApiId, apiId);
        return super.remove(queryWrapper);
    }

    @Override
    public Boolean setLatestFlag(String id, Boolean latestFlag) {
        LambdaUpdateWrapper<ApiVersionConfigDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApiVersionConfigDO::getId, id);
        updateWrapper.set(ApiVersionConfigDO::getLatestFlag, latestFlag);
        return super.update(updateWrapper);
    }

    @Override
    public Boolean setLatestFlagByApiId(String apiId, boolean latestFlag) {
        LambdaUpdateWrapper<ApiVersionConfigDO> updateWrapper = new LambdaUpdateWrapper<>();
        updateWrapper.eq(ApiVersionConfigDO::getApiId, apiId);
        updateWrapper.set(ApiVersionConfigDO::getLatestFlag, latestFlag);
        return super.update(updateWrapper);
    }

    @Override
    public List<ApiVersionConfigDO> queryByApiConfigIds(List<String> ids) {
        LambdaQueryWrapper<ApiVersionConfigDO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.in(ApiVersionConfigDO::getApiId, ids);
        return super.list(queryWrapper);
    }
}
